<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DECP后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/css/public.css" >
    <link rel="stylesheet" href="/admin/css/common.css" />
    <link rel="stylesheet" href="/layui/css/layui.css" />
</head>
<body pear-container>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="demoReload" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-table"
               lay-data="{ cellMinWidth: 80, page: true,id:'tableId', limit:10, url:'sysRole/queryPage', defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],skin: 'line',toolbar: '#role-toolbar-add'}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                <th lay-data="{field:'roleId', width:80, sort: true, fixed: true}">ID</th>
                <th lay-data="{field:'roleName', minWidth:80}">角色名称</th>
                <th lay-data="{field:'roleKey', minWidth:80}">角色Key</th>
                <th lay-data="{field:'roleCreationDate', minWidth:130, sort: true}">创建时间</th>
                <th lay-data="{field:'option', fixed: 'right',width:300,  align: 'center',toolbar:'#role-toolbar',unresize: true}">
                    操作
                </th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/html" id="role-toolbar-add">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="userSave">
        添加角色
    </button>

</script>
    <script type="text/html" id="role-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="rolePermissions">
        分配权限
    </button>
   <!-- <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="userModify">
        编辑信息
    </button>-->
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="roleResource">
        分配资源菜单
    </button>

</script>

<script src="/js/layui/layui.all.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function () {
        var table = layui.table;

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'rolePermissions') {
                var data = obj.data;
                parent.layer.open({
                    type: 1
                    ,
                    area: ['500px', '500px']
                    ,
                    title: '角色权限分配'
                    ,
                    resize: false
                    ,
                    offset: 'auto'
                    ,
                    id: data.id //防止重复弹出，写主键Id
                    ,
                    content: '<iframe frameborder="0" width="100%" height="100%" src="send_sys_role_allocationPermissions"/>'
                    ,
                    end: function () {
                        //窗口关闭，刷新列表
                        table.reload("tableId", {});
                        top.layerFrameConfig.iframeUserModify == null;
                    },
                    success: function (layero, index) {
                        top.layerFrameConfig.iframeUserModify = {
                            layer_index: index,
                            layer_layero: layero,
                            data: data //将数据保存到配置中，便于子页面获取
                        }
                    }
                });
            } else if (obj.event === 'roleResource') {
                var data = obj.data;
                parent.layer.open({
                    type: 1
                    ,
                    area: ['500px', '500px']
                    ,
                    title: '分配系统资源菜单'
                    ,
                    resize: false
                    ,
                    offset: 'auto'
                    ,
                    id: data.id //防止重复弹出，写主键Id
                    ,
                    content: '<iframe frameborder="0" width="100%" height="100%" src="send_sys_role_roleResource"/>'
                    ,
                    end: function () {
                        //窗口关闭，刷新列表
                        table.reload("tableId", {});
                        top.layerFrameConfig.iframeUserModify == null;
                    },
                    success: function (layero, index) {
                        top.layerFrameConfig.iframeUserModify = {
                            layer_index: index,
                            layer_layero: layero,
                            data: data //将数据保存到配置中，便于子页面获取
                        }
                    }
                });
            } else if (obj.event === 'edit') {
                var data = obj.data;
                parent.layer.open({
                    type: 1
                    , area: ['300px', '500px']
                    , title: '编辑系统角色信息'
                    , resize: false
                    , offset: 'auto'
                    , id: data.id //防止重复弹出，写主键Id
                    , content: '<iframe frameborder="0" width="100%" height="100%" src="send_sys_role_modify"/>'
                    , end: function () {
                        //窗口关闭，刷新列表
                        table.reload("tableId", {});
                        top.layerFrameConfig.iframeUserModify == null;
                    }, success: function (layero, index) {
                        top.layerFrameConfig.iframeUserModify = {
                            layer_index: index,
                            layer_layero: layero,
                            data: data //将数据保存到配置中，便于子页面获取
                        }
                    }
                });
            }
        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
            }
            , isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //  按条件查询
        var active = {
            userSave: function () { //添加
//                layer.msg("更新");
                parent.layer.open({
                    type: 1
                    , area: ['300px', '500px']
                    , title: '添加系统角色信息'
                    , resize: false
                    , offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    , content: '<iframe frameborder="0" width="100%" height="100%" src="send_sys_role_save"/>'
                    , end: function () {
                        //窗口关闭，刷新列表
                        table.reload("tableId", {});
                        top.layerFrameConfig.iframeUserModify == null;
                    }, success: function (layero, index) {
                        top.layerFrameConfig.iframeUserModify = {
                            layer_index: index,
                            layer_layero: layero,
                        }
                    }
                });
            }, reload: function () {
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('tableId', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        roleName: demoReload.val()
                    }
                });
            }
        };
    });
</script>
</body>
</html>
